//封装axios 的基础配置
import axios from 'axios'
import { serverUrl } from '@/views/utils/common';
const request = axios.create({
    baseURL:'/api',
    timeout: 10000
})


// 添加请求拦截器 
request.interceptors.request.use(config =>{
    if(sessionStorage.getItem('user')){
      let user = JSON.parse(sessionStorage.getItem('user'))
      config.headers.Authorization = 'Bearer '+ user.token;
    } 
    return config;
  }, error=> {

    return Promise.reject(error);
  });

// 添加响应拦截器
request.interceptors.response.use(response=>{

    return response.data;
  }, error=> {

    return Promise.reject(error);
  });

export default request;